from aiogram import F
from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.kbd import Back, Button, Cancel, Next
from aiogram_dialog.widgets.media import DynamicMedia

from poker_bot.core.models.enums.deposit import DepositStatus
from poker_bot.tg_bot.dialogs.extras import copy_start_data_to_ctx
from poker_bot.tg_bot.dialogs.getters.deposits import deposit_info_getter
from poker_bot.tg_bot.dialogs.getters.media import invoice_screenshot_getter
from poker_bot.tg_bot.dialogs.getters.users import user_role_getter
from poker_bot.tg_bot.dialogs.widgets import LocaleText
from poker_bot.tg_bot.states import DepositInfoSG

from .handlers import confirm_deposit_payment

deposit_details_window = Window(
    LocaleText("deposit-overview"),
    DynamicMedia(
        "invoice_screenshot", when=(F["user_is_admin"]) & (F["invoice_screenshot"])
    ),
    LocaleText("deposit-id", deposit_id="{deposit_id}"),
    LocaleText("deposit-status", status="{status_value}"),
    LocaleText("deposit-summ", summ="{summ}"),
    LocaleText("account-id", account_id="{account_id}"),
    LocaleText("user-username", username="{username}", when=F["user_is_admin"]),
    LocaleText("was-created", was_created="{was_created}"),
    Next(
        LocaleText("confirm-deposit-payment-btn"),
        when=(F["user_is_admin"]) & (F["status"] == DepositStatus.waiting_payment),
    ),
    Cancel(LocaleText("back-btn")),
    state=DepositInfoSG.deposit_info,
    getter=(deposit_info_getter, invoice_screenshot_getter, user_role_getter),
)

confirm_deposit_window = Window(
    LocaleText("confirm-deposit-payment-msg"),
    Button(
        LocaleText("confirm-btn"),
        id="confirm_payment",
        on_click=confirm_deposit_payment,
    ),
    Back(LocaleText("back-btn")),
    state=DepositInfoSG.confirm_deposit_payment,
)

deposit_details_dialog = Dialog(
    deposit_details_window,
    confirm_deposit_window,
    on_start=copy_start_data_to_ctx,
)
